package com.grape.springbootgradle20220520.base;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {
    public static void main(String[] args) {
        Queue<User> queue=new PriorityQueue<>(new UserComparator());
        queue.offer(new User("robin","A1"));
        queue.offer(new User("Tome","A2"));
        queue.offer(new User("jack","V1"));
        queue.offer(new User("lucy","V2"));
        System.out.println(queue.poll());
        System.out.println(queue.poll());
        System.out.println(queue.poll());
        System.out.println(queue.poll());
    }
}
class User {
    String name;
    String number;

    public User(String name, String number) {
        this.name = name;
        this.number = number;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", number='" + number + '\'' +
                '}';
    }
}
class UserComparator implements Comparator<User>{

    @Override
    public int compare(User o1, User o2) {
        if (o1.number.charAt(0)==o2.number.charAt(0)){
            return o1.number.compareTo(o2.number);
        }
        if (o1.number.charAt(0)=='V'){
            return -1;
        }
        return 1;
    }
}
